const cache = {}
const theme = {
  default() {
    if (!cache.default) {
      cache.default = import('./theme/turquoiseBlue.theme.scss')
    }
    return cache.default
  },
  theme2() {
    if (!cache.theme2) {
      cache.theme2 = import('./theme/emeraldGreen.theme.scss')
    }
    return cache.theme2
  },
  theme3() {
    if (!cache.theme3) {
      cache.theme3 = import('./theme/ceruleanBlue.theme.scss')
    }
    return cache.theme3
  }
}

let current = null

async function setTheme(name) {
  if (theme[name]) {
    let style = await theme[name]()
    if (current) {
      current.unuse()
    }
    style.use()
    current = style
  }
}

export default setTheme
